import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import path, { resolve } from 'path';

const pathResolve = (dir: string): any => {
  return resolve(__dirname, '.', dir);
};

const alias: Record<string, string> = {
  '@': pathResolve('./src/'),
};

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
      directoryAsNamespace: true, //解决不同文件夹下命名为Index.vue报命名冲突问题
    }),
  ],
  server: {
    host: '0.0.0.0', //解决vite use--host to expose
    port: 9090,
    open: false, //是否自动打开
  },
  resolve: {
    alias,
    // alias: [
    //   {
    //     find: '@',
    //     replacement: path.resolve(__dirname, 'src'),
    //   },
    // ],
  },
});
